#ifndef SUBJECT_H
#define SUBJECT_H
#include<vector>
#include"observer.h"
#include<memory>
using namespace std;
class Observer;
class Subject
{
protected:
    vector<shared_ptr<Observer> > observers;
public:
    virtual void notify() = 0;
    void attach(shared_ptr<Observer> observer)
    {
        observers.push_back(observer);
    }
    void detach(shared_ptr<Observer> observer)
    {
        for(auto it = observers.begin(); it != observers.end(); )
        {
            if(*it == observer)
            {
                it = observers.erase(it);
            }
            else
            {
                ++it;
            }
        }
    }
};
#endif